package com.vca.front.controller;

import com.vca.common.request.InvoiceRequest;
import com.vca.common.response.InvoicedDetailsResponse;
import com.vca.common.response.InvoicedListResponse;
import com.vca.common.response.InvoicedRecordResponse;
import com.vca.common.result.CommonResult;
import com.vca.common.utils.VcaUtil;
import com.vca.service.service.InvoiceRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Li
 * @description 发票小程序控制器
 * @date 2023-02-10 15:06
 */

@Slf4j
@RestController("InvoiceController")
@RequestMapping("api/front/invoice")
@Api(tags = "发票小程序控制器")
public class InvoiceController {

    @Autowired
    private InvoiceRecordService invoiceRecordService;


    @ApiOperation("开票")
    @PostMapping(value = "/invoice")
    public CommonResult invoice(@RequestBody InvoiceRequest request){
        Long upload = invoiceRecordService.settlementUpload(request);
        return upload.equals(0L)?CommonResult.failed():CommonResult.success(upload);
    }

    @ApiOperation("红冲")
    @PostMapping(value = "/creditNote")
    public CommonResult<String> creditNote(@RequestBody InvoiceRequest request){

        return invoiceRecordService.creditNote(request.getOrderNos())?CommonResult.success():CommonResult.failed();
    }

    /**
     * @description 查询可开票列表
     * @param orderNo
     * @author Li
     * @date 2023/2/9 17:19
     * @return {@link CommonResult}<{@link List}<{@link InvoicedListResponse}>>
     */
    @ApiOperation("可开票列表")
    @GetMapping("/invoicedList")
    public CommonResult<List<InvoicedListResponse>> invoicedList(@RequestHeader(value = "language",required = false) String language, String orderNo){
        return CommonResult.success(invoiceRecordService.getInvoiceList(language,orderNo));
    }

    /**
     * @description 发票记录
     * @author Li
     * @date 2023/2/10 11:27
     * @return {@link CommonResult}<{@link List}<{@link InvoicedListResponse}>>
     */
    @ApiOperation("发票记录")
    @GetMapping("/invoicedRecord")
    public CommonResult<List<InvoicedRecordResponse>> invoicedRecord(){
        return CommonResult.success(invoiceRecordService.getInvoicedRecord());
    }

    /**
     * @description  查看发票详情
     * @param invoiceId
     * @author Li
     * @date 2023/2/10 14:36
     * @return {@link CommonResult}<{@link InvoicedDetailsResponse}>
     */
    @ApiOperation("查看发票详情")
    @GetMapping("/invoicedDetails")
    public CommonResult<InvoicedDetailsResponse> invoicedDetails(Integer invoiceId){
        return CommonResult.success(invoiceRecordService.getInvoiceDetails(invoiceId));
    }

}
